using Gateway.Common.Enums;
using Gateway.IApplication.BaseInput;
using Gateway.IApplication.Tenant;
using Gateway.IApplication.Tenant.Input;
using Gateway.IQuery;
using Gateway.IQuery.Tenant;
using Gateway.IQuery.Tenant.Request;
using Gateway.IQuery.Tenant.Result;
using Gateway.UI.Api.Filters.Attributes;

namespace Gateway.UI.Api.Controllers;

/// <summary>
/// 租户服务
/// </summary>
public class TenantController : BaseController
{
    private readonly ITenantApp _app;
    private readonly ITenantQuery _query;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="app"></param>
    /// <param name="query"></param>
    public TenantController(ITenantApp app, ITenantQuery query)
    {
        _app = app;
        _query = query;
    }

    /// <summary>
    /// 创建
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("add"), Log(logType: LogTypeEnum.TenantOperate, logEvent: "创建了租户，租户名称:${TenantName}")]
    public async Task<bool> Add(CreateTenantInput input)
    {
        return await _app.Add(input);
    }

    /// <summary>
    /// 更新
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("update"), Log(logType: LogTypeEnum.TenantOperate, logEvent: "更新了租户，租户Id:${TenantId}")]
    public async Task<bool> Update(UpdateTenantInput input)
    {
        return await _app.Update(input);
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("remove"), Log(logType: LogTypeEnum.TenantOperate, logEvent: "删除了租户，租户Id:${Id}")]
    public async Task<bool> Remove(RemoveInput input)
    {
        return await _app.Remove(input);
    }

    /// <summary>
    /// 禁用/启用
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("disable"), Log(logType: LogTypeEnum.TenantOperate, logEvent: "禁用/启用了租户，租户Id:${Id}")]
    public async Task<bool> Disable(DisableInput input)
    {
        return await _app.Disable(input);
    }


    /// <summary>
    /// 获取分页列表
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost, Route("list/page")]
    public async Task<PageResult<TenantDetailResult>> GetPageList(TenantPageListRequest request)
    {
        return await _query.GetPageList(request);
    }

    /// <summary>
    /// 获取详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet, Route("detail/{id}")]
    public async Task<TenantDetailResult> GetDetail(string id)
    {
        return await _query.GetDetail(id);
    }
}